home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 …ember: Reference Library / Dev.CD Dec 97 RL.toast / What's New / Tool Chest / Testing & Debugging / Virtual User / Examples / External Tool Templates / CPlus Tool Template / ThreadedVUTool.vu < prev    next >
Encoding:
Text File  |  1997-10-15  |  4.6 KB  |  187 lines  |  [TEXT/MPS ]

  1. (*
  2.     File:        ThreadedVUTool.vu
  3.     
  4.     Contains:    
  5.         Virtual User 2.1a2 script for testing threaded external tool services. 
  6.         The basic threaded services are EchoThread and EchoNoThread.
  7.                 
  8.     
  9.     Written by:    Stuart Russell
  10.     
  11.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  12.     
  13.     Change History (most recent first):
  14.     
  15.                 01/10/95    SBR        modified for ETO.
  16.                 11/18/94    SBR        created.
  17.     
  18.     To Do:
  19. *)
  20.  
  21.  
  22. Libraries "ThreadedVUTool.vulib";
  23.  
  24. task ReturnErrorString( errorStringEntry )
  25. begin
  26.     if IsUndefined( errorStringEntry )
  27.         return "";
  28.     else
  29.         return errorStringEntry;
  30. end;
  31.  
  32. script TryThreading
  33. (
  34.     PauseThread1 := 600, 
  35.     PauseThread2 := 600, 
  36.     PauseThread3 := 600, 
  37.     PauseThread4 := 600, 
  38.     PauseNonThreaded := 180, 
  39.     randomPause := false,
  40.     doBeep := true,
  41.     beepEveryN := 0,
  42.     sleep_ticks := 1,
  43.     useLists := true,
  44.     run_continuously := false,
  45.     LaunchOnTarget := false
  46. )
  47. begin
  48.     ExternalToolTimeout(9999);
  49.     
  50.     if doBeep
  51.         doBeep := true;
  52.     else
  53.         doBeep := false;
  54.     
  55.     oldActorName := ActorName( 'waiting' );
  56.     
  57.     ActorName( oldActorName );
  58.     
  59.     m := ThreadedVUTool( "Initialize", LaunchOnTarget);    # Initialize the ThreadedVUTool.
  60.     println 'ThreadedVUTool( "Initialize"):    ',m;
  61.     if m[1] <> 0                                    # If error during initialization,
  62.     begin
  63.         println "ThreadedVUTool could not be initialized";        # print error
  64.         println "Error ", m[1], ". ", ReturnErrorString( m[3] );
  65.         exit;                                        # & exit this script.
  66.     end;
  67.     
  68.     if sleep_ticks >= 0
  69.     begin
  70.         m := ThreadedVUTool( "SetSleepTicks", sleep_ticks);    # set the sleep ticks for WaitNextEvent.
  71.         println "ThreadedVUTool( 'SetSleepTicks', {sleep_ticks}):    ",m;
  72.     end;
  73.     
  74.     rList := 
  75.     {
  76.         { {{{{1,{},{'gump'},{}},{{true,{{'325434t',23232,'ΩΩΩΩΩΩΩ'}}}},false},{}},{}} },
  77.         { 4 },
  78.         { true },
  79.         { false },
  80.         { 4 },
  81.         { true },
  82.         { false },
  83.         { 4 },
  84.         { true },
  85.         { false },
  86.         {}
  87.     };
  88.     
  89.     rListSize := card rList;
  90.     
  91.     if run_continuously
  92.         run_continuously := 99999999;
  93.     else
  94.         run_continuously := 0;
  95.         
  96.     for run_continuously := run_continuously to 0 step -1
  97.     begin
  98.         if randomPause
  99.         begin
  100.             PauseNonThreaded := random( 0, PauseNonThreaded );
  101.             PauseThread1 := random( 0, PauseThread1 );
  102.             PauseThread2 := random( 0, PauseThread2 );
  103.             PauseThread3 := random( 0, PauseThread3 );
  104.             PauseThread4 := random( 0, PauseThread4 );
  105.         end;
  106.         
  107.         if useLists 
  108.         begin
  109.             itemS := rList[random(1,rListSize)];
  110.             item1 := rList[random(1,rListSize)];
  111.             item2 := rList[random(1,rListSize)];
  112.             item3 := rList[random(1,rListSize)];
  113.             item4 := rList[random(1,rListSize)];
  114.         end;
  115.         else
  116.         begin
  117.             itemS := {}; item1 := {}; item2 := {}; item3 := {}; item4 := {}; 
  118.         end;
  119.  
  120.         if PauseNonThreaded
  121.         begin
  122.             theSync1 := ThreadedVUTool('EchoNoThread',itemS,PauseNonThreaded,doBeep, beepEveryN) async: false;
  123.         end;
  124.         
  125.         if PauseThread1
  126.         begin
  127.             theAsync1 := ThreadedVUTool('EchoThread',item1,PauseThread1,doBeep, beepEveryN) async: true;
  128.         end;
  129.         
  130.         if PauseThread2
  131.         begin
  132.             theAsync2 := ThreadedVUTool('EchoThread',item2,PauseThread2,doBeep, beepEveryN) async: true;
  133.         end;
  134.         
  135.         if PauseThread3
  136.         begin
  137.             theAsync3 := ThreadedVUTool('EchoThread',item3,PauseThread3,doBeep, beepEveryN) async: true;
  138.         end;
  139.         
  140.         if PauseThread4
  141.         begin
  142.             theAsync4 := ThreadedVUTool('EchoThread',item4,PauseThread4,doBeep, beepEveryN) async: true;
  143.         end;
  144.         
  145.         ActorName( oldActorName );
  146.  
  147.         while (theSync1[1] = 1) or (theAsync1[1] = 1) or (theAsync2[1] = 1) or (theAsync3[1] = 1) or (theAsync4[1] = 1)
  148.         begin
  149.             #println "1: ", theAsync1, "        2: ", theAsync2, "        3: ", theSync1;
  150.             
  151.             if PauseThread1 and (theAsync1[1] = 1) 
  152.                 theAsync1 := ThreadedVUTool('poll',theAsync1[2]) ;
  153.             
  154.             if PauseThread2 and (theAsync2[1] = 1) 
  155.                 theAsync2 := ThreadedVUTool('poll',theAsync2[2]) ;
  156.  
  157.             if PauseThread3 and (theAsync3[1] = 1) 
  158.                 theAsync3 := ThreadedVUTool('poll',theAsync3[2]) ;
  159.  
  160.             if PauseThread4 and (theAsync4[1] = 1) 
  161.                 theAsync4 := ThreadedVUTool('poll',theAsync4[2]) ;
  162.  
  163.             if PauseNonThreaded and (theSync1[1] = 1) 
  164.                 theSync1 := ThreadedVUTool('poll',theSync1[2]) ;
  165.         end;
  166.         if theAsync1
  167.             if theAsync1[1] <> 0 or theAsync1[2] <> item1
  168.                 println "ERROR theAsync1 = {theAsync1}, item1 = {item1}";
  169.         if theAsync2
  170.             if theAsync2[1] <> 0 or theAsync2[2] <> item2
  171.                 println "ERROR theAsync2 = {theAsync2}, item2 = {item2}";
  172.         if theAsync3
  173.             if theAsync3[1] <> 0 or theAsync3[2] <> item3
  174.                 println "ERROR theAsync3 = {theAsync3}, item3 = {item3}";
  175.         if theAsync4
  176.             if theAsync4[1] <> 0 or theAsync4[2] <> item4
  177.                 println "ERROR theAsync4 = {theAsync4}, item4 = {item4}";
  178.         if theSync1
  179.             if theAsync1[1] <> 0 or theSync1[2] <> itemS
  180.                 println "ERROR theSync1 = {theSync1}, itemS = {itemS}";
  181.         println "1:", theAsync1, "  2:", theAsync2, "  3:", theAsync3, "  4:", theAsync4, "  5:", theSync1;
  182.     end;
  183.  
  184.     ThreadedVUTool('quit') ;
  185. end;
  186.  
  187.